package com.simple.util.math.function;

/**
 * @program: simple_tools
 * @description: 阶乘函数
 * @author: ChenWenLong
 * @create: 2019-11-15 11:47
 **/
public class FactorialFunction {

    /**
     * 功能描述:
     * 〈递归方式实现阶乘函数〉
     *
     * @params : [num]
     * @return : int
     * @author : cwl
     * @date : 2019/11/15 11:47
     */
    public static int recursion(int num){
        if(num == 1){
            return 1;
        }else if(num == 2){
            return 2;
        }else{
            return num*recursion(num-1);
        }
    }

    /**
     * 功能描述:
     * 〈非递归方法实现阶乘函数〉
     *
     * @params : [num]
     * @return : int
     * @author : cwl
     * @date : 2019/11/15 11:49
     */
    public static int unRecursion(int num){
        int jiecheng = 1;
        if(num == 0){
            return 0;
        }
        for (int i = 1; i <= num; i++) {
            jiecheng*=i;
        }
        return jiecheng;
    }
}
